package com.example.myapplication8;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import java.util.StringTokenizer;

import static android.icu.lang.UCharacter.GraphemeClusterBreak.T;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button botton1 = findViewById(R.id.button);//头插
        Button botton2 = findViewById(R.id.button2);//尾插
        Button botton3 = findViewById(R.id.button3);//查找元素删除
        Button botton4 = findViewById(R.id.button4);//查找元素插入
        Button botton5 = findViewById(R.id.button5);//排序
        Button botton6 = findViewById(R.id.button6);//输出
        Button botton7 = findViewById(R.id.button7);//find
        final EditText editText = findViewById(R.id.editText);
        final EditText editText1 = findViewById(R.id.editText2);

        final Product product = new Product();
        botton1.setOnClickListener(new View.OnClickListener() {


            @Override
            public void onClick(View v) {
                StringTokenizer Tokenizer = new StringTokenizer(editText1.getText().toString());
                String[] ant = new String[3];
                int a = 0;
                while (Tokenizer.hasMoreTokens()) {
                    ant[a] = Tokenizer.nextToken();
                    a++;
                }
                product.addToFront(ant[0], ant[1], ant[2]);
                editText.setText(product.toString());
            }

        });

        botton2.setOnClickListener(new View.OnClickListener()

        {
            @Override
            public void onClick(View v) {
                StringTokenizer Tokenizer = new StringTokenizer(editText1.getText().toString());
                String[] ant = new String[3];
                int a = 0;
                while (Tokenizer.hasMoreTokens()) {
                    ant[a] = Tokenizer.nextToken();
                    a++;
                }
                product.addToRear(ant[0], ant[1], ant[2]);
                editText.setText(product.toString());
            }

        });
        botton3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              product.remove(editText1.getText().toString());
              editText.setText(product.toString());
            }

        });
        botton4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                StringTokenizer Tokenizer=new StringTokenizer(editText1.getText().toString());
                String [] ant=new String[4];
                int a=0;
                while(Tokenizer.hasMoreTokens())
                {
                    ant[a]=Tokenizer.nextToken();
                    a++;
                }
                product.addAfter(ant[0],ant[1],ant[2],ant[3]);
                editText.setText(product.toString());
            }

        });
        botton5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                product.selectsort();
                editText.setText(product.toString());
            }

        });
        botton6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                editText.setText(product.toString());
            }

        });
        botton7.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                editText.setText(product.find(editText1.getText().toString()));
            }

        });
    }
    }


